#include "NumberUi.h"
using namespace std;
CNumberUi::CNumberUi()
{
}

CNumberUi::~CNumberUi()
{
}

bool CNumberUi::init()
{
	if (!Node::init()){
		return false;
	}
	this->setVisible(false);

	m_pNumberLabel = Label::createWithTTF("", "fonts/arial.ttf", 8);
	m_pNumberLabel->enableShadow();
	this->addChild(m_pNumberLabel);
	return true;
}

void CNumberUi::resetNumber(int num ,int sort)
{
	
	m_pNumberLabel->stopAllActions();
	if (!this->isVisible()){	
		this->setVisible(true);
		m_pNumberLabel->setScale(1);
		m_pNumberLabel->setPositionY(getPosition().y - 2);
		m_pNumberLabel->setOpacity(255);
		m_nNum = num;
		
	}
	else{
		m_pNumberLabel->setOpacity(255);
		m_nNum += num;
	}
	if (sort == GETHARM){
		m_pNumberLabel->setColor(Color3B(255, 0, 0));
		m_pNumberLabel->setString(to_string(m_nNum));
		m_pNumberLabel->setPosition(0, 20);
		
	}
	else if (sort == GETHP){
		m_pNumberLabel->setColor(Color3B(144,238,144));
		m_pNumberLabel->setString("+"+to_string(m_nNum));
		m_pNumberLabel->setPosition(0, 22);
	}
	else if (sort == GETMP){
		m_pNumberLabel->setColor(Color3B(100,149,237));
		m_pNumberLabel->setString("+" + to_string(m_nNum));
		m_pNumberLabel->setPosition(0, 23);
	}
	

	FadeOut* fadeOut = FadeOut::create(1.5);
	MoveBy* move = MoveBy::create(1, Vec2(0, 2));
	ScaleTo* scale = ScaleTo::create(1, 1.5);
	CCCallFunc* callbk = CCCallFunc::create([&]{this->setVisible(false); m_nNum = 0; });
	Sequence* seq = Sequence::createWithTwoActions(fadeOut, callbk);
	m_pNumberLabel->runAction(move);
	m_pNumberLabel->runAction(scale);
	m_pNumberLabel->runAction(seq);
}
